package com.ferrlo.web.controller;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ferrlo.servlet.SampleImageCaptchaService;
import com.octo.captcha.service.CaptchaServiceException;


@Controller
public class ImageController {

	@RequestMapping(value="/imageVal.do")
	@ResponseBody
	public Map<String, Object> isCorrect(HttpServletRequest request,HttpServletResponse response){
		Map<String, Object> map = new HashMap<String, Object>();

		Boolean isResponseCorrect = Boolean.FALSE;
		String captchaId = request.getSession().getId();
		String responsestr = request.getParameter("captcha_no");
		try {
			isResponseCorrect = SampleImageCaptchaService.getInstance()
					.validateResponseForID(captchaId, responsestr);
			if (isResponseCorrect) {
				map.put("result", true);
			} else {
				map.put("result", false);
			}
		} catch (CaptchaServiceException e) {
		
		}

		return map;
	}
}
